home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 76 / XENIATGM66.iso / Indiana Jones / Indiana Jones.exe / RESOURCE / PREVIEW.GOB / cog_pru_stairpit.cog < prev    next >
Text File  |  1999-11-15  |  16KB  |  584 lines

  1.  
  2. # Jones 3D Cog Script
  3. #
  4. # PRU_stairpit.cog
  5. # Blocks will push you into the pit if you aren't careful.  They also form a stairway out. 
  6. # [GGJ] [PKM]
  7. #
  8. # (C) 1998 LucasArts Entertainment Co. All Rights Reserved
  9. # ========================================================================================
  10.  
  11. symbols
  12.     message entered
  13.     message pulse
  14.     message    arrived
  15.     message    timer
  16.     message touched
  17.     message    exited
  18.     message    startup
  19.     message    blocked
  20.  
  21.     thing   block0
  22.     thing   block1          
  23.     thing   block2
  24.     thing   block3        mask=0x409
  25.     thing   block4        mask=0x409
  26.     thing   block5        mask=0x409
  27.     #thing   block6
  28.     thing    staircam
  29.     thing    stairCamTarg
  30.  
  31.     thing    Plate2mL
  32.     thing    Plate4mL
  33.     thing    Plate6mL
  34.     thing    Plate8mL
  35.     thing    Plate10mL
  36.     thing    Plate12mL
  37.  
  38.     thing    Plate2mR
  39.     thing    Plate4mR
  40.     thing    Plate6mR
  41.     thing    Plate8mR
  42.     thing    Plate10mR
  43.     thing    Plate12mR
  44.     
  45. #    thing    fakeBlock0
  46. #    thing    fakeBlock1
  47. #    thing    fakeBlock2
  48. #    thing    fakeBlock3
  49. #    thing    fakeBlock4
  50. #    thing    fakeBlock5
  51.     #thing    fakeBlock6
  52.     
  53.     thing    blockGhost0
  54.     thing    blockGhost1
  55.     thing    blockGhost2
  56.     thing    blockGhost3
  57.     thing    blockGhost4
  58.     thing    blockGhost5
  59.     #thing    blockGhost6
  60.     
  61.     thing    backGhost0
  62.     thing    backGhost1
  63.     thing    backGhost2
  64.     thing    backGhost3
  65.     thing    backGhost4
  66.     thing    backGhost5
  67.     #thing    backGhost6
  68.     
  69.     thing    player                local
  70.     
  71.     float   baseMoveSpeed=3.5    local    // How long it takes to push out (was) how fast the blocks push out
  72.     float   moveSpeed=4.4            // Block speed adjusted for difficulty.
  73.     float    retractSpeed=0.5         // How fast they retract if you jump back the way you came
  74.     float    autoRetractSpeed=3.0    // How fast they retract automatically, after they're all out
  75.     float   pulseTime=3.0            // After a block starts pushing out, pause before next one starts
  76.     float    autoRetract=10.0        // Delay before blocks start retracting automatically
  77.         
  78.     int     counter=0            local
  79.     int        retractCounter=0    local
  80.     int     crosscheck=0         local
  81.     int        out=0                local
  82.     
  83.     int        blockTrack0            local
  84.     int        blockTrack1            local
  85.     int        blockTrack2            local
  86.     int        blockTrack3            local
  87.     int        blockTrack4            local
  88.     int        blockTrack5            local
  89.  
  90.     int        startDifficulty        local        // The difficulty setting at the time the puzzle was triggered.    
  91.     
  92.     flex    f_XDist                local
  93.     flex    f_YDist                local
  94.     flex    f_ZDist                local
  95.     thing    invisiBox=-1        local          mask=0x080
  96.     vector    v_modvec            local
  97.     vector    v_targetpos            local
  98.     sector    targetsector        local
  99.     
  100.     template    boxTpl        #currently set in Marcus to "1M oil drum c," will be changed to "1M aimable invisible cube."                             
  101.     
  102.     surface    hangR0        linkID=1    #with your back to the wall these hang ledges are to your right
  103.     surface    hangR1        linkID=1
  104.     surface    hangR2        linkID=1
  105.     surface    hangR3        linkID=1
  106.     surface    hangR4        linkID=1
  107.     
  108.     surface    hangL0        linkID=1    #with your back to the wall these hang ledges are to your left
  109.     surface    hangL1        linkID=1
  110.     surface    hangL2        linkID=1
  111.     surface    hangL3        linkID=1
  112.     surface    hangL4        linkID=1
  113.     surface    hangL5        linkID=1
  114.     
  115.     surface    hangE0        linkID=1
  116.     surface    hangE1        linkID=1
  117.     surface    hangE2        linkID=1
  118.     surface    hangE3        linkID=1
  119.     surface    hangE4        linkID=1
  120.     surface    hangE5        linkID=1
  121.     #surface    hangE6        linkID=1
  122.     
  123.     surface    musTrigger
  124.     surface    retractTrigger
  125.     surface    retractTrigger2
  126.  
  127.     
  128.     flex hangDistR0=0.5            local
  129.     flex hangDistR1=0.4            local
  130.     flex hangDistR2=0.3            local
  131.     flex hangDistR3=0.2            local
  132.     flex hangDistR4=0.1            local
  133.  
  134.     flex hangDistL0=-0.6        local
  135.     flex hangDistL1=-0.5        local
  136.     flex hangDistL2=-0.4        local
  137.     flex hangDistL3=-0.3        local
  138.     flex hangDistL4=-0.2        local
  139.     flex hangDistL5=-0.1        local
  140.  
  141.     flex retractBlocks            local
  142.  
  143.     int currentBlock        local
  144.     int currentSurface        local
  145.     int    bSurfaceFound        local
  146.     int    hanging=0            local
  147.     
  148.     int    bBlockFound=0        local
  149.     int out0=0                local
  150.     int out1=0                local
  151.     int out2=0                local
  152.     int out3=0                local
  153.     int out4=0                local
  154.     int out5=0                local
  155.     int out6=0                local
  156.     int    musOnce=0            local
  157.     
  158.     surface triggerface     mask=0x405
  159.     surface    retractface        mask=0x405
  160.     
  161.     sound    blocksnd=olv_quetzdoor_move_c.wav    local        #fol_in_scrapehard_long.wav      local
  162.     sound    blockStopSnd=olv_quetzdoor_stop_c.wav    local
  163.     sound    musStairpit=mus_gen_awechord1.wav    local
  164.  
  165.     sound        wav0=olv_outside_a02.wav        local
  166.     sound        wav1=olv_outside_a06.wav        local
  167.     sound       wav2=shw_amb3.wav                local
  168.     sound       wav3=shw_amb6.wav                local
  169.     int            numsounds=4                        local
  170.     int            numlocl=5                        local
  171.     int            soundoff=0                        local
  172.     int            sndnum                            local
  173.     int            cnt                                local
  174.     int            allblocksout=0                    local
  175.     thing        soundPos0                    nolink
  176.     thing        soundPos1                    nolink
  177.     thing        soundPos2                    nolink
  178.     thing        soundPos3                    nolink
  179.     thing        soundPos4                    nolink
  180.     surface        soundonsurf0
  181.     surface        soundonsurf1
  182.     surface        soundoffsurf0
  183.     surface        soundoffsurf1
  184.  
  185.     sector        safeCubby
  186.  
  187.  
  188.  
  189. end
  190. # ========================================================================================
  191. code
  192.  
  193. startup:
  194.  
  195.     player = GetLocalPlayerThing();
  196.  
  197.     # When the blocks are in the wall, they should be "fakeblocks" so that Indy can't hang from them.
  198. #    for (currentBlock = 0; (currentBlock <= 5); currentBlock = currentBlock + 1)
  199. #    {
  200. #        SetThingFlags(block0[currentBlock], 0x80000);
  201. #    }
  202.  
  203.     SetThingFlags(Plate2mL, 0x80000);
  204.     SetThingFlags(Plate2mR, 0x80000);
  205.     SetThingFlags(Plate4mL, 0x80000);
  206.     SetThingFlags(Plate4mR, 0x80000);
  207.     SetThingFlags(Plate6mL, 0x80000);
  208.     SetThingFlags(Plate6mR, 0x80000);
  209.     SetThingFlags(Plate8mL, 0x80000);
  210.     SetThingFlags(Plate8mR, 0x80000);
  211.     SetThingFlags(Plate10mL, 0x80000);
  212.     SetThingFlags(Plate10mR, 0x80000);
  213.     SetThingFlags(Plate12mL, 0x80000);
  214.     SetThingFlags(Plate12mR, 0x80000);
  215.     return;
  216.  
  217. # ========================================================================================
  218. entered:
  219.  
  220.     if (GetSenderRef() == safeCubby)
  221.     {
  222.         UpdateDifficulty(startDifficulty);
  223.         return;
  224.     }
  225.  
  226.     # We only care about entered messages from surfaces.
  227.     if (GetSenderType() != 6) return;
  228.  
  229.     if ((GetSenderRef() == soundoffSurf0) || (GetSenderRef() == soundoffSurf1))
  230.     {
  231.         soundoff = 1;
  232.            return;
  233.     }
  234.     if ((GetSenderRef() == soundonSurf0) || (GetSenderRef() == soundonSurf1))
  235.     {
  236.         soundoff = 0;
  237.            return;
  238.     }
  239.  
  240.     if (((GetSenderRef() == retractTrigger) || (GetSenderRef() == retractTrigger2)) && (allblocksout == 1))
  241.     {
  242.         call retractBlocks;
  243.         allblocksout=0;
  244.         crosscheck = 0;
  245.         return;
  246.     }
  247.     
  248.     if ((GetSenderRef() == musTrigger) && (musOnce == 0))
  249.     {
  250.         musOnce = 1;
  251.         PlaySoundLocal(musStairpit, 1.0, 0.0, 0x0, 1);
  252.         SetTimer(1.0);
  253.         return;
  254.     }
  255.     
  256.     # Indy lands on the second platform.
  257.     if ((GetSenderRef() == triggerface) && (crosscheck == 0))
  258.     {
  259.         crosscheck = 1;
  260.  
  261.         # Remove the fake block and add blocks you can hang from.
  262. #       SetThingFlags(fakeBlock0[0], 0x80000);
  263. #        ClearThingFlags(block0[0], 0x80000);
  264.  
  265.         // The movement time is increased by 20% of the base move speed per difficulty level under 5.
  266.         // I.e., difficulty 4 is 20% longer, diff. 3 is 40% longer, diff. 0 is 100% longer.
  267.         startDifficulty = GetDifficulty();
  268.         moveSpeed = baseMoveSpeed + (((5 - startDifficulty) * 0.2) * baseMoveSpeed);
  269.         # The first block starts to move, and the pulse will trigger the rest.
  270.         MoveThingtoPos(block0, GetThingPos(blockGhost0), movespeed);
  271.         out0[0] = 0;
  272.         blockTrack0 = PlaySoundThing(blocksnd, block0, 1.0, 7.5, 30.0, 0x1);
  273.         SetPulse(pulseTime);
  274.         return;
  275.     }
  276.         
  277.     # If Indy jumps back to the entrance
  278.     if ((GetSenderRef() == retractface) && (crosscheck == 1))
  279.     {
  280.         
  281.         Print("entered retract trigger-surface");
  282.         # Shut off the pulse.
  283.         SetPulse(0);
  284.         counter = 0;
  285.         crosscheck = 0;
  286.         retractCounter = 0;
  287.         
  288.         # Move the blocks back.
  289.         for (currentBlock = 0; (currentBlock <= 6); currentBlock = currentBlock + 1)
  290.         {
  291.             MoveThingToPos(block0[currentBlock], GetThingPos(backGhost0[currentBlock]), retractSpeed);
  292.             out0[currentBlock] = 1;
  293.         }
  294.         return;
  295.     }
  296.  
  297.     # Code below checks to see if Indy is hanging from a platform at the base of one of the blocks.
  298.  
  299.     f_YDist = 0.1; # plug in y value here
  300.     f_ZDist = 0.25; # plug in z value here            #changed from 3 for benefit of smallest block
  301.  
  302.     bSurfaceFound = 0;
  303.  
  304.     for (currentSurface = 0; (currentSurface < 5) && !bSurfaceFound; currentSurface = currentSurface + 1)
  305.     {
  306.         // Check to see if we're hanging off the left edge of our block surfaces.
  307.  
  308.         if (GetSenderRef() == hangR0[currentSurface])
  309.         {
  310.             f_XDist = hangDistR0[currentSurface];
  311.             bSurfaceFound = 1;
  312.         }
  313.     }
  314.  
  315.     if (!bSurfaceFound)
  316.     {
  317.         // We're not hanging off the right side - check for the left side.
  318.  
  319.         for (currentSurface = 0; (currentSurface < 6) && !bSurfaceFound; currentSurface = currentSurface + 1)
  320.         {
  321.             if (GetSenderRef() == hangL0[currentSurface])
  322.             {
  323.                 f_XDist = hangDistL0[currentSurface];
  324.                 bSurfaceFound = 1;
  325.             }
  326.         }
  327.     }
  328.  
  329.     # Establish a target near Indy at f_XDist, f_Ydist, f_ZDist
  330.     # Fill in offsets as needed.  0.1 = 1m
  331.     # Positive values are right (x) and forward (y) of thing center
  332.     # Z values are offset from thing center (itself offset from insert point)
  333.     # The mysterious zero vector parm in CreateThingAtPos() is for PYR
  334.     # xdist (defined above) is one half of block height, plus one
  335.  
  336.     # Create an invisible box above Indy.  (used in "Touched" section)
  337.  
  338.     if (bSurfaceFound)
  339.     {
  340.         v_modvec = VectorSet(f_XDist, f_YDist, f_ZDist);
  341.         v_targetpos = VectorAdd(VectorTransformToOrient(player, v_modvec), GetThingPos(player));    
  342.         targetsector = FindNewSectorFromThing(player, v_targetpos);
  343.         if (invisiBox != -1)
  344.         {
  345.             DetachThing(invisiBox);
  346.             DestroyThing(invisiBox);
  347.         }
  348.         invisiBox = CreateThingAtPos(boxTpl, targetsector, v_targetpos, '0 0 0');
  349.         CaptureThing(invisiBox); # no capture, no work
  350.         AttachThingToThing(invisiBox, player); # track his move
  351.     }
  352.  
  353.     if ((GetSenderID() == 1)&& ((GetSenderRef() != triggerFace) || (GetSenderRef() != retractFace)))
  354.     {
  355.         hanging = 1;
  356.     }
  357.     return;
  358.  
  359. # ========================================================================================
  360. exited:
  361.  
  362.     # Destroy the invisible box created when Indy was hanging.
  363.  
  364.     bSurfaceFound = 0;
  365.  
  366.     for (currentSurface = 0; (currentSurface < 5) && !bSurfaceFound; currentSurface = currentSurface + 1)
  367.         if (GetSenderRef() == hangR0[currentSurface])
  368.             bSurfaceFound = 1;
  369.  
  370.     if (!bSurfaceFound)
  371.         for (currentSurface = 0; (currentSurface < 6) && !bSurfaceFound; currentSurface = currentSurface + 1)
  372.             if (GetSenderRef() == hangL0[currentSurface])
  373.                 bSurfaceFound = 1;
  374.  
  375.     if (bSurfaceFound && invisiBox != -1)
  376.     {
  377.         DetachThing(invisiBox);
  378.         DestroyThing(invisiBox);
  379.         invisiBox = -1;
  380.     }
  381.  
  382.     if ((GetSenderID() == 1) && (hanging == 1))
  383.     {
  384.         hanging=0;
  385.     }
  386.  
  387. return;
  388.  
  389. # ........................................................................................
  390. pulse:
  391.  
  392.     # Move each block out
  393.     counter = counter + 1;
  394. #    SetThingFlags(fakeBlock0[counter], 0x80000);
  395. #    ClearThingFlags(block0[counter], 0x80000);
  396.     
  397.     MoveThingToPos(block0[counter], GetThingPos(blockGhost0[counter]), movespeed);
  398.     blocktrack0[counter] = PlaySoundThing(blocksnd, block0[counter], 1.0, 7.5, 30.0, 0x1);
  399.     out0[counter] = 0;
  400.  
  401.     if (counter == 5)
  402.     {
  403.         SetPulse(0);
  404.         counter = 0;
  405.         retractCounter = 0;
  406.     }
  407.     return;
  408.  
  409. # ........................................................................................    
  410. arrived:
  411.  
  412.     bBlockFound=0;
  413.  
  414.     for (currentBlock = 0; (currentBlock <= 5) && !bBlockFound; currentBlock = currentBlock + 1)
  415.         if ((GetSenderRef() == Block0[currentBlock]))
  416.             bBlockFound = 1;
  417.  
  418.     if (!bBlockFound)
  419.         return;
  420.  
  421.     currentBlock = currentBlock - 1;
  422.  
  423.     # "Out" is "0" when the blocks are moving out.
  424.     if (out0[currentBlock] == 0)
  425.     {
  426.         ClearSurfaceFlags(hangR0[currentBlock], 0x1000000);
  427.         ClearSurfaceFlags(hangL0[currentBlock], 0x1000000);
  428.         ClearSurfaceFlags(hangE0[currentBlock], 0x1000000);
  429.         out0[currentBlock] = 1;
  430.         StopSound(blockTrack0[currentBlock], 0.0);
  431.         PlaySoundThing(blockStopSnd, block0[currentBlock], 1.0, 7.5, 30.0, 0);
  432.         
  433.                 
  434.         if (hanging == 1)
  435.         {
  436.             SetActorFlags(player, 0x200000);
  437.             DetachThing(player);
  438.         }
  439.  
  440.         if (GetSenderRef() == Block5)
  441.         {
  442.             #SetTimer(autoRetract);
  443.             allblocksout=1;
  444.         }
  445.  
  446.         ClearThingFlags(Plate2mL[5 - currentBlock], 0x80000);
  447.         ClearThingFlags(Plate2mR[5 - currentBlock], 0x80000);
  448.  
  449.         return;
  450.     }
  451.     else
  452.     {
  453.         # "Out" is "1" when the blocks are moving back in.
  454.  
  455.         #SetThingFlags(Block0[currentBlock], 0x80000);
  456.         #ClearThingFlags(FakeBlock0[currentBlock], 0x80000);
  457.  
  458.         SetSurfaceFlags(hangR0[currentBlock], 0x1000000);
  459.         SetSurfaceFlags(hangL0[currentBlock], 0x1000000);
  460.         SetSurfaceFlags(hangE0[currentBlock], 0x1000000);
  461.  
  462.         StopSound(blockTrack0[currentBlock], 0.0);
  463.         PlaySoundThing(blockStopSnd, block0[currentBlock], 1.0, 7.5, 30.0, 0);
  464.         
  465.         out0[currentBlock] = 0;
  466.  
  467.         if (GetSenderRef() == Block0)
  468.         {
  469.             #crosscheck = 0;
  470.         }
  471.  
  472.         SetThingFlags(Plate2mL[5 - currentBlock], 0x80000);
  473.         SetThingFlags(Plate2mR[5 - currentBlock], 0x80000);
  474.  
  475.         return;
  476.     }
  477.  
  478.  
  479.     
  480.     #if ((hanging == 1) && (GetSenderRef() == block0[counter]))
  481.     #{
  482.     #    if (invisiBox != -1)
  483.     #    {
  484.     #        DetachThing(invisiBox);
  485.     #        DestroyThing(invisiBox);
  486.     #        invisiBox = -1;
  487.     #    }
  488.     #    SetActorFlags(player, 0x200000);
  489.     #    DetachThing(player);
  490.     #    ClearSurfaceFlags(hangR0, 0x1000000);
  491.     #    ClearSurfaceFlags(hangL0, 0x1000000);
  492.     #    ClearSurfaceFlags(hangE0, 0x1000000);
  493.     #}
  494.     
  495.     return;   
  496. # ........................................................................................
  497. timer:
  498.     if (soundoff == 1) return;
  499.     
  500.     sndnum = rand()*numsounds;
  501.     cnt = rand()*numlocl;
  502.     PlaySoundThing(wav0[sndnum], soundPos0[cnt], 0.8, 10.0, 30.0, 0);
  503.     SetTimer(rand() + 1.0);
  504.  
  505.     return;
  506.  
  507. # ........................................................................................
  508. touched:    
  509.  
  510.     if (GetSourceRef() == player)
  511.         return;
  512.  
  513.     if (GetSenderRef() == invisiBox)
  514.     {
  515.         Print("Sender is invisiBox!");
  516.         SetActorFlags(player, 0x200000);
  517.         if (invisiBox != -1)
  518.         {
  519.             DetachThing(invisiBox);
  520.             DestroyThing(invisiBox);
  521.             invisiBox = -1;
  522.         }
  523.         DetachThing(player);
  524.     }
  525.  
  526.     return;
  527.     
  528. # ........................................................................................
  529. blocked:
  530. Print("blocked");
  531.  
  532. if (GetSenderRef() == block5)
  533. {
  534.     Sleep(0.5);
  535.     Print("inside blocked if statement");
  536.     MoveThingToPos(block5, GetThingPos(blockGhost5), movespeed);
  537.     #blocktrack5 = PlaySoundThing(blocksnd, block5, 1.0, 7.5, 30.0, 0x1);
  538. }
  539. if (GetSenderRef() == block4)
  540. {
  541.     Sleep(0.5);
  542.     Print("inside blocked if statement");
  543.     MoveThingToPos(block4, GetThingPos(blockGhost4), movespeed);
  544.     #blocktrack4 = PlaySoundThing(blocksnd, block4, 1.0, 7.5, 30.0, 0x1);
  545.  
  546. }
  547.  
  548. return;
  549. # ........................................................................................
  550. retractBlocks:
  551. MakeMeStop();
  552.  
  553. AttachThingToThing(stairCamTarg, stairCam);
  554. SetCameraFocus(2, stairCam);
  555. SetCameraSecondaryFocus(2, stairCamTarg);
  556. SetCurrentCamera(2);
  557. SetCameraFOV(100, 0, 0.0);
  558.  
  559. Rotate(stairCam, -100, 1, 5);
  560.  
  561.  
  562. # Retract all of the blocks
  563. for (retractCounter = 0; retractcounter < 6; retractcounter = retractcounter + 1)
  564. {
  565.     blocktrack0[retractCounter] = PlaySoundThing(blocksnd, block0[retractCounter], 1.0, 7.5, 30.0, 0x1);
  566.     #MoveToFrame(block0[retractCounter], 0, autoRetractSpeed);
  567.     MoveThingToPos(block0[retractCounter], GetThingPos(backGhost0[retractCounter]), autoretractSpeed);
  568.     out0[retractCounter] = 1;
  569.     Sleep(0.1);
  570. }
  571. Sleep(5.0);
  572.  
  573. ClearActorFlags(player, 0x200000);
  574. SetCurrentCamera(1);
  575. Rotate(stairCam, 100, 1, 5);
  576.  
  577. return;
  578.  
  579.  
  580. # ........................................................................................
  581. end
  582.